#!/usr/bin/sh
PATH=/usr/bin:/usr/local/bin:/usr/sbin:/opt/csw/bin
export PATH

LOGFILE=`mktemp /tmp/amanda-server-install.XXXXXXXXXXX`
if [ $? -ne 0 ]; then
    echo "Unable to mktemp!" 1>&2
    exit 1
fi
export LOGFILE
amanda_user=amandabackup; export amanda_user
amanda_group=disk; export amanda_group
# BASEDIR is set by either in pkginfo, or if not set, by pkgadd at installtime.
# Unfortunately, it messes things up to have basedir="/".
[ "x${BASEDIR}" = "x/" ] && basedir="" || basedir=${BASEDIR}
AMANDAHOMEDIR="${basedir}%%AMANDAHOMEDIR%%"; export AMANDAHOMEDIR
os=`uname`; export os
wanted_shell=/usr/bin/bash; export wanted_shell
LOGDIR="${basedir}%%LOGDIR%%"; export LOGDIR
INSTALL_LOG=${LOGDIR}/install.log; export INSTALL_LOG
SYSCONFDIR="${basedir}/etc"; export SYSCONFDIR

# See packaging/common/ for shell function libraries.
# ---------- Common functions ------------
%%COMMON_FUNCTIONS%%
%%PRE_INST_FUNCTIONS%%

# -------- End Common functions ----------
logger "Preparing to install: Amanda Server %%VERSION%%"
create_user
check_user_group "${amanda_group}" || add_group "${amanda_group}"
check_user_supplemental_group "tape" || add_group "tape"
check_user_shell "${wanted_shell}"
check_user_homedir "${AMANDAHOMEDIR}"
check_homedir || create_homedir
create_logdir

logger "Preinstall done."

cat $LOGFILE > $INSTALL_LOG && rm $LOGFILE || \
    echo "Amanda preinstall logs can be found in '$LOGFILE'."
